Creating a new database is really simple in Schematic, simply create your schema files for the database then run the migrations using migrations:execute
Firstly however we'll cover the syntax for configuring a schema file.
Below is a sample of the schema file which is created with the migrations:generate
command:
schematic:
##Just the base of the file configs, names the file and defines the version
name: Schematic
## The name of the application
version: 1.4.1
## The version of the application this file is for
database:
## The area where the database settings are defined, all database and file configs are defined here
general:
## General database settings should be defined here for the table
name: schematic
## Name of the database to run this table import on
charset: utf8
## Charset to use for this table
collation: utf8_general_ci
## Collation to use for this table
engine: InnoDB
## Database engine to use for this table
tables:
## Within tables you define the table this file represents
hello_world:
## This should be the name of your table
fields:
## Within fields you will define the fields for your table
id:
## The key should be the name of your field
type: int(11)
## For each field you must define, a type, you define the type as you would in MySQL e.g. int(11), varchar(128) enum('YES', 'NO'), etc...
'null': false
## Null must be defined with single quotes in YAML
unsigned: true
##Unsigned and any other boolean settable configurations for fields are set as real booleans
autoIncrement: true
## Auto-increment does what you'd assume, it sets a field to auto-increment if it is the right format, e.g. an integer and has an index.
index: 'PRIMARY KEY'
## You can set the same kind of indexes as the same as you would in your database, e.g. PRIMARY_KEY, INDEX, UNIQUE, etc... you are also able to define composite keys, simply set them as another primary key
user_id:
# In this example we are going to show how to define a foreign key
type: int(11)
'null': false
unsigned: true
index: 'INDEX'
foreignKeys:
## Foreign keys are quite easy to define, just setup a foriegn key array
table: users
## Setup the related table
field: id
## Setup the related table id
on:
## Setup the on even
update: CASCADE
## Then as per the format of your database setup your action
delete: RESTRICT
## As above
name:
## As above this is the name for the field we are defining
type: varchar(128)
## As above we are just defining the type with it's length
'null': false
## As above we are just defining a null false
rename: full_name
## To rename this field you would use the rename field, and set the new name within here
created_date:
type: datetime
'null': false